package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.Product;
import com.eling.elcms.travel.service.IProductManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ProductController extends BaseFormController{
     
	@Autowired
	private IProductManager productManager;
	
	@RequestMapping("/api/product/query")
    @ResponseBody
    public List<Product> query(@ModelAttribute Product cond){
    	return productManager.query(cond); 
    }
	
	@RequestMapping("/api/product/search")
    @ResponseBody
    public List<Product> search(@ModelAttribute SearchCondition sc,@ModelAttribute Product cond){
		sc.setQueryCondition(cond);
    	return productManager.search(sc); 
    }
	
	@RequestMapping("/api/product/save")
    @ResponseBody
    public Product save(@ModelAttribute@ModelFilling Product product) {
		return productManager.save(product);
    }
	
	@RequestMapping("/api/product/{pkProduct}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkProduct) {
		productManager.remove(pkProduct);
	    return new Msg("删除成功");
	}
	
	@RequestMapping("/api/product/savepro")
    @ResponseBody
    public Product savePro(@ModelAttribute@ModelFilling Product product) {
		return productManager.savePro(product);
    }
	
	/**
	 * 查签约中的产品
	 * @param cond
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/product/queryproductbymail")
    @ResponseBody
    public List<Product> queryProdByMail(@ModelAttribute Product cond){
    	return productManager.queryProdByMail(cond); 
    }
}
